#   引入生成浏览器的包
from selenium import webdriver

import time
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC

#   实例化一个浏览器
browser = webdriver.Chrome()
browser.implicitly_wait(10)
browser.get('https://image.baidu.com/')

#   三种写法
input = browser.find_element_by_id('kw')
# input_second = browser.find_element_by_css_selector('#q')
# input_third = browser.find_element_by_xpath('//*[@id=q]')

# print(input_first, input_second, input_third)
# browser.close()

# try:
#     browser.get('http://www.baidu.com')
#     input = browser.find_element_by_id('kw')
#     input.send_keys('PYthon')
#     input.send_keys(Keys.ENTER)
#     wait = WebDriverWait(browser, 10)
#     wait.until(EC.presence_of_all_elements_located((By.ID, 'content_left')))
#     print(browser.current_url)
#     print(browser.get_cookie())
#     print(browser.page_source)
# finally:
#     browser.close()

input.send_keys('古装壁纸')
input.send_keys(Keys.ENTER)
browser.execute_script('window.open()')
browser.execute_script('window.open()')
browser.switch_to.window(browser.window_handles[1])
browser.get('https://image.baidu.com/')
input = browser.find_element_by_id('kw')
input.send_keys('美女壁纸')
input.send_keys(Keys.ENTER)
# time.sleep(2)
# browser.switch_to.window(browser.window_handles[0])

# time.sleep(1)
# input.clear()
# input.send_keys('iPad')
# button = browser.find_element_by_class_name('bg s_btn')
# button = browser.find_element_by_id('s_search')
# button.click()

